<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Rails::Rack::Logger</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../css/github.css" type="text/css" media="screen" />
<script src="../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Class</span> 
            Rails::Rack::Logger 
            
                <span class="parent">&lt; 
                    
                    <a href="../../ActiveSupport/LogSubscriber.html">ActiveSupport::LogSubscriber</a>
                    
                </span>
            
        </h1>
        <ul class="files">
            
            <li><a href="../../../files/railties/lib/rails/rack/logger_rb.html">railties/lib/rails/rack/logger.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>Sets log tags, logs the request, calls the app, and flushes the logs.</p>

    </div>
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Logger.html#method-i-call">call</a>,
              </li>
            
              
              <li>
                <a href="Logger.html#method-i-call_app">call_app</a>,
              </li>
            
              
              <li>
                <a href="Logger.html#method-i-compute_tags">compute_tags</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>N</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Logger.html#method-c-new">new</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Logger.html#method-i-started_request_message">started_request_message</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
    
      <div class="sectiontitle">Class Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-c-new">
            
              <b>new</b>(app, taggers = nil)
            
            <a href="Logger.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/ffa9540fd361eb34c445568b66abf283b9e658f8/railties/lib/rails/rack/logger.rb#L11" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/rack/logger.rb, line 11</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>(<span class="ruby-identifier">app</span>, <span class="ruby-identifier">taggers</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-ivar">@app</span>          = <span class="ruby-identifier">app</span>
  <span class="ruby-ivar">@taggers</span>      = <span class="ruby-identifier">taggers</span> <span class="ruby-operator">||</span> []
  <span class="ruby-ivar">@instrumenter</span> = <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Notifications</span>.<span class="ruby-identifier">instrumenter</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                  
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-call">
            
              <b>call</b>(env)
            
            <a href="Logger.html#method-i-call" name="method-i-call" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-call_source')" id="l_method-i-call_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/ffa9540fd361eb34c445568b66abf283b9e658f8/railties/lib/rails/rack/logger.rb#L17" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-call_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/rack/logger.rb, line 17</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">call</span>(<span class="ruby-identifier">env</span>)
  <span class="ruby-identifier">request</span> = <span class="ruby-constant">ActionDispatch</span><span class="ruby-operator">::</span><span class="ruby-constant">Request</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">env</span>)

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:tagged</span>)
    <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">tagged</span>(<span class="ruby-identifier">compute_tags</span>(<span class="ruby-identifier">request</span>)) { <span class="ruby-identifier">call_app</span>(<span class="ruby-identifier">request</span>, <span class="ruby-identifier">env</span>) }
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">call_app</span>(<span class="ruby-identifier">request</span>, <span class="ruby-identifier">env</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
              
      <div class="sectiontitle">Instance Protected methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-call_app">
            
              <b>call_app</b>(request, env)
            
            <a href="Logger.html#method-i-call_app" name="method-i-call_app" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-call_app_source')" id="l_method-i-call_app_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/ffa9540fd361eb34c445568b66abf283b9e658f8/railties/lib/rails/rack/logger.rb#L29" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-call_app_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/rack/logger.rb, line 29</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">call_app</span>(<span class="ruby-identifier">request</span>, <span class="ruby-identifier">env</span>)
  <span class="ruby-comment"># Put some space between requests in development logs.</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">development?</span>
    <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">debug</span> <span class="ruby-string">''</span>
    <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">debug</span> <span class="ruby-string">''</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-ivar">@instrumenter</span>.<span class="ruby-identifier">start</span> <span class="ruby-string">'action_dispatch.request'</span>, <span class="ruby-identifier">request</span><span class="ruby-operator">:</span> <span class="ruby-identifier">request</span>
  <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span> <span class="ruby-identifier">started_request_message</span>(<span class="ruby-identifier">request</span>)
  <span class="ruby-identifier">resp</span> = <span class="ruby-ivar">@app</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>)
  <span class="ruby-identifier">resp</span>[<span class="ruby-number">2</span>] = <span class="ruby-operator">::</span><span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">BodyProxy</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">resp</span>[<span class="ruby-number">2</span>]) { <span class="ruby-identifier">finish</span>(<span class="ruby-identifier">request</span>) }
  <span class="ruby-identifier">resp</span>
<span class="ruby-keyword">rescue</span>
  <span class="ruby-identifier">finish</span>(<span class="ruby-identifier">request</span>)
  <span class="ruby-identifier">raise</span>
<span class="ruby-keyword">ensure</span>
  <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">LogSubscriber</span>.<span class="ruby-identifier">flush_all!</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-compute_tags">
            
              <b>compute_tags</b>(request)
            
            <a href="Logger.html#method-i-compute_tags" name="method-i-compute_tags" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-compute_tags_source')" id="l_method-i-compute_tags_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/ffa9540fd361eb34c445568b66abf283b9e658f8/railties/lib/rails/rack/logger.rb#L57" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-compute_tags_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/rack/logger.rb, line 57</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">compute_tags</span>(<span class="ruby-identifier">request</span>)
  <span class="ruby-ivar">@taggers</span>.<span class="ruby-identifier">collect</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">tag</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">case</span> <span class="ruby-identifier">tag</span>
    <span class="ruby-keyword">when</span> <span class="ruby-constant">Proc</span>
      <span class="ruby-identifier">tag</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">request</span>)
    <span class="ruby-keyword">when</span> <span class="ruby-constant">Symbol</span>
      <span class="ruby-identifier">request</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">tag</span>)
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">tag</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-started_request_message">
            
              <b>started_request_message</b>(request)
            
            <a href="Logger.html#method-i-started_request_message" name="method-i-started_request_message" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Started GET “/session/new” for 127.0.0.1 at 2012-09-26 14:51:42 -0700</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-started_request_message_source')" id="l_method-i-started_request_message_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/ffa9540fd361eb34c445568b66abf283b9e658f8/railties/lib/rails/rack/logger.rb#L49" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-started_request_message_source" class="dyn-source">
                <pre><span class="ruby-comment"># File railties/lib/rails/rack/logger.rb, line 49</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">started_request_message</span>(<span class="ruby-identifier">request</span>)
  <span class="ruby-string">'Started %s &quot;%s&quot; for %s at %s'</span> <span class="ruby-operator">%</span> [
    <span class="ruby-identifier">request</span>.<span class="ruby-identifier">request_method</span>,
    <span class="ruby-identifier">request</span>.<span class="ruby-identifier">filtered_path</span>,
    <span class="ruby-identifier">request</span>.<span class="ruby-identifier">ip</span>,
    <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">to_default_s</span> ]
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    